/*
 * main.cc
 *
 *   Created on: 2010-3-24     
 *  Description: 
 *    Copyright: 2010 @ ICT Li Heyuan
 */

#include "../include/RSATools.h"

#include <string>
#include <iostream>
using std::string;
using std::cin;
using std::cout;
using std::endl;

#include <cryptopp/aes.h>
#include <cryptopp/modes.h>

#include "../include/AESTools.h"

void testRsaTools()
{
	RSATools rsa(1024);
	cout << "公钥n " << rsa.getModulus() << endl;
	cout << "公钥e " << rsa.getPublicExponent() << endl;

	RSATools rsa2(rsa.getPublicExponent(), rsa.getModulus());
	string plain("1234567890123456"), cliper, recovered;
	cout << "原文:" << endl << plain << endl;
	//	cliper = rsa2.encryptWithBase64(plain);
	cin >> cliper;
	cout << "加密:" << endl << cliper << endl;
	recovered = rsa.decryptWithBase64(cliper);
	cout << "还原: " << endl << recovered << endl;
}

void testAesTools()
{
	/*	byte key[] =
	 { 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213,
	 214, 215 };
	 string key_str((char *) key, sizeof(key));*/
	string key_str = "1234567892023456";
	AESTools aes(key_str);

	string plain("[12,20]");

	cout << "加密前" << endl << plain << endl;

	string cipher0 = aes.encryptWithBase64(plain);
	cout << "Tool加密" << endl << cipher0 << endl;

	string cipher;
	cin >> cipher;
	cout << "AES加密后" << endl << cipher << endl;

	AESTools aes2(key_str);
	string plain_after = aes2.decryptWithBase64(cipher);
	cout << "AES解密后" << endl << plain_after << endl;
}

int main()
{
	//	testRsaTools();
	testAesTools();
	return 0;
}
